package cn.huxingyuan.service.impl;

import cn.huxingyuan.article.domain.Article;
import cn.huxingyuan.article.query.ArticleQuery;
import cn.huxingyuan.mapper.ArticleMapper;
import cn.huxingyuan.service.IArticleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author Hu
 * 2025/8/8 16:50
 */
@Service
public class ArticleServiceImpl implements IArticleService {
    @Autowired
    private ArticleMapper articleMapper;
    @Override
    public Article findById(Long id) {
        return articleMapper.findById(id);
    }

    @Override
    public List<Article> findAll() {
        return articleMapper.findAll();
    }

    @Override
    public void add(Article article) {
        article.setCreateTime(new Date());
        articleMapper.add(article);
    }

    @Override
    public void update(Article article) {
        article.setUpdateTime(new Date());
        articleMapper.update(article);
    }

    @Override
    public void deleteById(Long id) {
        articleMapper.deleteById(id);
    }

    @Override
    public void batchDelete(List<Long> ids) {
        articleMapper.batchDelete(ids);
    }

    @Override
    public PageInfo<Article> pageAll(ArticleQuery articleQuery) {
        PageHelper.startPage(articleQuery.getPage(), articleQuery.getSize());
        List<Article> pageInfo = articleMapper.pageAll(articleQuery);
        return new PageInfo<>(pageInfo);
    }

    @Override
    public List<Article> getRelative(Long id, Long articleType) {
        return articleMapper.getRelative(id,articleType);
    }
}
